/*
 * @Author: gonghairun
 * @Date: 2021-11-30 12:26:01
 * @LastEditors: gonghairun
 * @LastEditTime: 2021-11-30 12:26:01
 * @Description: 
 */

/**
 * 函数防抖
 * @param func
 * @param wait
 * @returns {function(...[*]=)}
 */
export const debounce = (func, wait = 1500) => {
    let timeout;
    return function() {
        let context = this;
        let args = arguments;
        if (timeout) clearTimeout(timeout);
        timeout = setTimeout(() => {
            func.apply(context, args)
        }, wait);
    }
}
/**
 * 函数节流
 * @param func
 * @param wait
 * @returns {function(...[*]=)}
 */
 export const throttle = (func, wait = 1500) => {
    let timeout;
    return function() {
        let context = this;
        let args = arguments;
        if (!timeout) {
            timeout = setTimeout(() => {
                timeout = null;
                func.apply(context, args)
            }, wait)
        }
    }
}
